package com.autonavi.yunda.yunji.core.vo.response;

import com.autonavi.yunda.yunji.core.enums.FunctionStatus;
import com.autonavi.yunda.yunji.core.enums.FunctionType;
import com.autonavi.yunda.yunji.core.model.dto.FunctionConfigDTO;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.sql.Timestamp;
import java.util.Set;

/**
 * @author sunzhenbang
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class FunctionConfigVO {
    private Long id;
    private String projectId;
    private String name;
    private String params;
    private String description;
    private FunctionType type;
    private FunctionStatus status;
    private String version;
    private String debugResult;
    private String functionScript;
    private String createUser;
    private String updateUser;
    private Timestamp createTime;
    private Timestamp updateTime;
    private Set<String> projectIds;

    public static FunctionConfigVO fromDto(FunctionConfigDTO dto) {
        return FunctionConfigVO.builder()
                .id(dto.getId())
                .name(dto.getName())
                .params(dto.getParams())
                .description(dto.getDescription())
                .type(dto.getType())
                .status(dto.getStatus())
                .version(dto.getVersion())
                .debugResult(dto.getDebugResult())
                .functionScript(dto.getFunctionScript())
                .createUser(dto.getCreateUser()).updateUser(dto.getUpdateUser())
                .createTime(dto.getCreateTime()).updateTime(dto.getUpdateTime())
                .build();
    }
}
